<%= render partial: 'subnav' %>

<% if @messages.any? %>
  <%= form_with url: batch_delete_messages_path do |f| %>
    <table class="data zebra with_select_all" width="100%" cellspacing=0>
    <tr>
      <th width="3%"></th>
      <th width="15%"><%= @direction == :in ? "From" : "To" %></th>
      <th width="17%"><%= @direction == :in ? "Received" : "Sent" %></th>
      <th width="60%">Subject</th>
    </tr>
    <% @messages.each do |message| %>
      <tr class="<%= message.has_been_read? ? "" : "bold" %>">
        <td><%= check_box_tag "delete_#{message.short_id}" %></td>
        <td>
          <div style="white-space:nowrap;">
            <% if @direction == :in %>
              <% if message.author %>
                <%= styled_user_link message.author %>
              <% else %>
                <%= message.author_username %>
              <% end %>
              <%= message.hat.to_html_label if message.hat %>
            <% else %>
              <%= styled_user_link message.recipient %>
            <% end %>
          </div>
        </td>
        <td><%= how_long_ago_label(message.created_at) %></td>
        <td><a href="/messages/<%= message.short_id %>"><%= message.subject
          %></a></td>
      </tr>
    <% end %>
    </table>
    <%= f.submit "Delete Selected" %>
  <% end %>
<% else %>
  <p>
  You do not have any <%= @direction == :in ? "" : "sent" %> private
    messages.
  </p>
<% end %>

<p>
  Compose Message
</p>

<%= render partial: 'form', locals: { new_message: @new_message, replying: false } %>
